home *** CD-ROM | disk | FTP | other *** search
- unit EmpForm;
-
- {
- This program demonstrates using TClientDataSet in a distributed data
- application. The data comes from a separate OLE Automation server,
- so before running this project you must compile and run EmpServ.dpr.
- }
-
- interface
-
- uses
- SysUtils, Forms, Dialogs, ExtCtrls, StdCtrls, Mask, Classes,
- DBClient, Db, Controls, DBCtrls, ComCtrls;
-
- type
- TEmployeeForm = class(TForm)
- Label2: TLabel;
- UpdateButton: TButton;
- UndoButton: TButton;
- QueryButton: TButton;
- DBText1: TDBText;
- FirstName: TDBEdit;
- LastName: TDBEdit;
- PhoneExt: TDBEdit;
- HireDate: TDBEdit;
- Salary: TDBEdit;
- EmpData: TDataSource;
- DBNavigator1: TDBNavigator;
- Employees: TClientDataSet;
- RemoteServer1: TRemoteServer;
- StatusBar1: TStatusBar;
- procedure QueryButtonClick(Sender: TObject);
- procedure UpdateButtonClick(Sender: TObject);
- procedure UndoButtonClick(Sender: TObject);
- procedure EmployeesReconcileError(DataSet: TClientDataSet;
- E: EReconcileError; UpdateKind: TUpdateKind; var Action: TReconcileAction);
- procedure EmpDataDataChange(Sender: TObject; Field: TField);
- end;
-
- var
- EmployeeForm: TEmployeeForm;
-
- implementation
-
- {$R *.DFM}
-
- procedure TEmployeeForm.QueryButtonClick(Sender: TObject);
- begin
-
- { Get data from the server. The number of records retrieved is dependent on
- the PacketRecords property of TClientDataSet. As the user scrolls through
- the data, additional records a retrieved in separate data packets. }
-
- Employees.Close;
- Employees.Open;
-
- end;
-
- procedure TEmployeeForm.UpdateButtonClick(Sender: TObject);
- begin
-
- { Apply any edits. The parameter indicates the number of errors which
- are allowed before the updating is aborted. A value of -1 indicates that
- all successful updates be applied regardless of the number of errors. }
-
- Employees.ApplyUpdates(-1);
- end;
-
- procedure TEmployeeForm.UndoButtonClick(Sender: TObject);
- begin
-
- { Here we demonstrate a new feature in TClientDataSet, the ability to
- undo changes in reverse order. The True parameter indicates that the
- cursor should be repositioned to record association with the change.
- If False is passed, the cursor postion remains unchanged. }
-
-
- Employees.UndoLastChange(True);
-
- end;
-
- procedure TEmployeeForm.EmployeesReconcileError(DataSet: TClientDataSet;
- E: EReconcileError; UpdateKind: TUpdateKind; var Action: TReconcileAction);
- var
- EmpNo: Variant;
- begin
-
- { This is a very simple error handler for the reconcile process. If there
- are any errors during the updates on the server we will be notified here
- to display the employee an error and choose an action to take. }
-
- EmpNo := VarToStr(DataSet.Fields[0].OldValue);
- ShowMessage(Format('Emp#: %s, %s', [EmpNo, E.Message]));
-
- { The Action parameter indicates what to do following the error. The
- raSkip value means we should leave the record in the change log and keep
- processing. We could also specify raRevert to remove the change log
- entry or raAbort to abort the reconcile operation. }
-
- Action := raSkip;
-
- end;
-
- procedure TEmployeeForm.EmpDataDataChange(Sender: TObject; Field: TField);
- begin
-
- { This code is used to update the status bar to show the number of
- records that have been retrieved an our relative position with the dataset. }
-
- with Employees do
- if Active then
- StatusBar1.Panels[1].Text := Format(' %d of %d', [RecNo, RecordCount]);
-
- end;
-
-
- end.
-